// ctrls\SimpleHtmlStatic.cpp : implementation file
//

#include "stdafx.h"
#include "SimpleHtmlStatic.h"


// CSimpleHtmlStatic

IMPLEMENT_DYNAMIC(CSimpleHtmlStatic, CStatic)

CSimpleHtmlStatic::CSimpleHtmlStatic()
{
	m_isTextPrepared = false;

	m_rgbBackground	= ::GetSysColor(COLOR_BTNFACE);

	m_rgbHighlight	= RGB(255,0,0);
	m_isUnderlineWhenHighlight	= true;

}

CSimpleHtmlStatic::~CSimpleHtmlStatic()
{
}


BEGIN_MESSAGE_MAP(CSimpleHtmlStatic, CStatic)
	ON_WM_PAINT()
	ON_WM_SIZE()
	ON_WM_ERASEBKGND()
END_MESSAGE_MAP()



// CSimpleHtmlStatic message handlers



void CSimpleHtmlStatic::OnPaint()
{
	CPaintDC dc(this); // device context for painting
	// TODO: Add your message handler code here
	// Do not call CStatic::OnPaint() for painting messages

	CRect rctClient;
	GetClientRect(rctClient);	
	
	// Draw the background
	dc.FillSolidRect(rctClient, m_rgbBackground);

	if ( !m_isTextPrepared )
	{
		rctClient.InflateRect(-5,-5);
		m_htmlDrawer.PrepareDraw(&dc, m_strScript, m_Font, rctClient,0);
		m_isTextPrepared = true;
	}

	// Draw the HTML
	m_htmlDrawer.Draw(&dc, m_rgbHighlight, m_isUnderlineWhenHighlight);
	
	

}

void CSimpleHtmlStatic::OnSize(UINT nType, int cx, int cy)
{

	CStatic::OnSize(nType, cx, cy);

	m_isTextPrepared = false;
	Invalidate(true);

	// TODO: Add your message handler code here
}

BOOL CSimpleHtmlStatic::OnEraseBkgnd(CDC* pDC)
{
	// TODO: Add your message handler code here and/or call default
	return TRUE;
	//return CStatic::OnEraseBkgnd(pDC);
}
